﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.SysDept.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.SysDept;
/// <summary>
/// 添加系统部门服务
/// </summary>
public class InsertSysDeptService : ApiBase<RequestInsertSysDeptModel>
{
    /// <summary>
    /// 系统部门仓储
    /// </summary>
    public SysDeptRep sysDeptRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new SysDeptModel();

        model.ParentId = Parameter.ParentId;
        model.Ancestors = Parameter.Ancestors;
        model.DeptName = Parameter.DeptName;
        model.OrderNum = Parameter.OrderNum;
        model.Leader = Parameter.Leader;
        model.Phone = Parameter.Phone;
        model.Email = Parameter.Email;
        model.Status = Parameter.Status;
        model.DelFlag = "0";
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;

        var res = sysDeptRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = sysDeptRep.GetSysDeptByDeptId(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}

